import tools

def email_contact(psqlMgr, text_pth, uuid, hostPort):
	doc_info = psqlMgr.query('select * from doctors where email="kathia@waterlilywellness.com"')
	doc_info = doc_info[0]

	appoints = psqlMgr.query('select * from appointments where uuid="' + uuid + '"')
	appoints = appoints[0]


	appointment_day = str(appoints['month']) + '/' + str(appoints['day']) + '/' + str(appoints['year'])
	appointment_hour = tools.get_Time_string(appoints['hour'], appoints['minute'])


	msg = tools.read_file(text_pth)
	msg = msg.replace('<!-- doctor_name -->', doc_info['name'])
	msg = msg.replace('<!-- address -->', doc_info['address'])
	msg = msg.replace('<!-- email -->', doc_info['email'])

	msg = msg.replace('<!-- patient -->', appoints['first_name'])
	msg = msg.replace('<!-- patient last name -->', appoints['last_name'])
	msg = msg.replace('<!-- date -->', appointment_day)
	msg = msg.replace('<!-- time -->', appointment_hour)
	msg = msg.replace('<!-- phone -->', appoints['phone_number'])
	msg = msg.replace('<!-- patient email -->', appoints['email'])
	msg = msg.replace('<!-- uuid -->', uuid)
	msg = msg.replace('<!-- complain -->', appoints['visit_reason'])
	msg = msg.replace('<!-- session type -->', str(appoints['session_type']))
	msg = msg.replace('<!-- session time -->', str(appoints['session_time']))

	if hostPort == 8080: msg = msg.replace('<!-- register link -->', 'http://localhost:8080/confirm_appointment?uuid=' + uuid)
	else: msg = msg.replace('<!-- register link -->', 'http://waterlilywellness.com/confirm_appointment?uuid=' + uuid)

	if hostPort == 8080: 
		msg = msg.replace('<!-- remove appointment link -->', 'http://localhost:8080/remove_appointment?uuid=' + uuid)
	else: msg = msg.replace('<!-- remove appointment link -->', 'http://waterlilywellness.com/remove_appointment?uuid=' + uuid)

	return msg

